package router

import (
	"data-center/api/http/handlers/file"
	"data-center/api/http/handlers/search"
	"data-center/api/http/handlers/source"
	"data-center/api/http/handlers/system"
	"data-center/api/http/handlers/task"
	"data-center/pkg/database/mongodb"
	"data-center/pkg/queue"

	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

// SetupRouter 设置路由
func SetupRouter(r *gin.Engine, db *gorm.DB, mongoClient *mongodb.Client, producer queue.Producer) {
	// API版本组
	v1 := r.Group("/api/v1")

	// 获取MongoDB集合
	taskCollection := mongoClient.GetCollection("news", "tasks")
	fileCollection := mongoClient.GetCollection("news", "files")
	sourceCollection := mongoClient.GetCollection("news", "sources")

	// 注册各模块路由
	taskHandler := task.NewHandler(db, taskCollection, producer)
	taskHandler.RegisterRoutes(v1)

	fileHandler := file.NewHandler(db, fileCollection, producer)
	fileHandler.RegisterRoutes(v1)

	sourceHandler := source.NewHandler(db, sourceCollection)
	sourceHandler.RegisterRoutes(v1)

	searchHandler := search.NewHandler()
	searchHandler.RegisterRoutes(v1)

	systemHandler := system.NewHandler(db, taskCollection, producer)
	systemHandler.RegisterRoutes(v1)
}
